package cc.zy.base.businesses.service.impl;

import java.util.*;

import cc.zy.base.businesses.entity.*;
import cc.zy.base.businesses.mapper.*;
import cc.zy.base.common.entity.FebsConstant;
import cc.zy.base.common.entity.QueryRequest;
import cc.zy.base.businesses.service.IStudentService;
import cc.zy.base.common.exception.FebsException;
import cc.zy.base.common.utils.SortUtil;
import cc.zy.base.monitor.entity.SystemLog;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * Service实现
 *
 * @author Jiangjinlin
 * @date 2021-01-25 11:45:25
 */
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    private final StudentMapper studentMapper;


    @Override
    public IPage<Student> selectStudentDetailList(Student student, QueryRequest request, Integer tabVal) {
        if (student != null && student.getStuName() != null) {
            student.setStuName(student.getStuName().trim());
        }

        if (tabVal == 1 && tabVal != null){
            Page<Student> page = new Page<>(request.getPageNum(), request.getPageSize());
            page.setSearchCount(false);
            page.setTotal(baseMapper.countStudentPoolDetail(student));
            SortUtil.handlePageSort(request, page, "id", FebsConstant.ORDER_ASC, false);

            return studentMapper.selectStudentPoolDetailPage(page, student);
        }else if (tabVal == 2 && tabVal != null){
            Page<Student> page = new Page<>(request.getPageNum(), request.getPageSize());
            page.setSearchCount(false);
            page.setTotal(baseMapper.countStudentDetail(student));
            SortUtil.handlePageSort(request, page, "id", FebsConstant.ORDER_ASC, false);

            return studentMapper.selectStudentDetailPage(page, student);
        }else {
            return null;
        }

    }
}